//
//  MyMachineViewController.m
//  SmartCup
//
//  Created by Kendama on 2017/5/24.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "MyMachineViewController.h"

@interface MyMachineViewController ()
/** 设备视图 **/
@property(nonatomic,strong) MachineView *machineView;
/** 删除按钮 **/
@property(nonatomic,strong) UIButton *deleteButton;
@end

@implementation MyMachineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)refreshBaseControlValue {
    [self setNavigationTitle:@"我的设备" titleColor:[UIColor whiteColor]];
    [self setLeftButtonImage:[UIImage imageNamed:@"nav_icon_back"]];
    self.navigationBar.backgroundColor = [UIColor colorWithHexString:@"3E76F6"];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F1F3F9"];
    [self layoutSubviews];
    
}

- (void)layoutSubviews {
    __weak UIView *superView = self.view;
    [self.machineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top).with.offset(64);
        make.width.mas_equalTo(superView);
        make.height.mas_equalTo(px1920Height(740));
    }];
    
    [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.machineView.mas_bottom).with.offset(px1920Height(519));
        make.left.mas_equalTo(superView).with.offset(px1080Width(48));
        make.right.mas_equalTo(superView).with.offset(-px1080Width(48));
        make.height.mas_equalTo(px1920Height(148));
    }];
}


- (MachineView *)machineView
{
    if(!_machineView)
    {
        UIView *superView = self.view;
        _machineView = [[MachineView alloc]init];
        _machineView.device = self.device;
        [superView addSubview:_machineView];
    }
    return _machineView;
}

- (UIButton *)deleteButton
{
    if(!_deleteButton)
    {
        __weak UIView *superView = self.view;
        _deleteButton = [[UIButton alloc]init];
        [superView addSubview:_deleteButton];
        [_deleteButton setTitle:@"删除" forState:UIControlStateNormal];
        [_deleteButton setBackgroundImage:[UIImage imageNamed:@"button_delete_nor"] forState:UIControlStateNormal];
        [_deleteButton setBackgroundImage:[UIImage imageNamed:@"button_delete_nor"] forState:UIControlStateHighlighted];
        [_deleteButton.titleLabel setFont:[UIFont systemFontOfSize:px1080Width(52)]];
        [_deleteButton addTarget:self action:@selector(didClickDeleteButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteButton;
}

- (void)didClickDeleteButton {
    NSMutableArray *data = [[NSMutableArray alloc] init];
    [data addObjectsFromArray:[[DTCBluetoothDataBaseManager sharedInstance] getAllDevice]];
    if (data.count > 0) {
        [[DTCBluetoothManager shareInstance] disconnectDevice:data[0]];
    }
    [[DTCBluetoothDataBaseManager sharedInstance] deleteAllDevice];
    [SVProgressHUD showSuccessWithStatus:@"删除设备成功"];
    DTCSAVE_OBJECT(@"NO", MATCH);

    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
